package internet_04;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

//        Student s = new Student();
//        s.address = "西安";
//        System.out.println(s);
public class Demo01 {
    public static void main(String[] args)throws Exception {
        //获取Class对象
        Class<?> c = Class.forName("myReflect.itheima_02.Student");
        //获取对象属性
        Field age = c.getDeclaredField("age");
        //获取无参构造方法
        Constructor<?> con = c.getDeclaredConstructor();

        //用反射,创建对象(学生)
        Object obj = con.newInstance();

        //暴力反射
        age.setAccessible(true);//注意是暴力反射谁(age)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        age.set(obj,18);

        System.out.println(obj);
    }
}
